/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.edu.utfpr.controlador;

import br.com.caelum.vraptor.*;
import br.edu.utfpr.bean.Poltrona;
import br.edu.utfpr.bean.Voo;
import br.edu.utfpr.dao.DaoPoltrona;
import br.edu.utfpr.dao.DaoVoo;
import java.util.List;

/**
 * @author guardezi
 */
@Resource
public class VooController {

    private final Result result;
    private final DaoVoo dao;
    private final DaoPoltrona daoPoltrona;

    public VooController(Result result, DaoVoo dao, DaoPoltrona daoPoltrona) {
        this.result = result;
        this.dao = dao;
        this.daoPoltrona = daoPoltrona;

    }

    @Path("/cadastrovoo")
    public void voo() {
        result.include("cadastro", "Cadastro VOO");

    }

    @Path("/gravarVoo")
    public void Gravar(Voo v) {
        v = dao.gravar(v);
        for (char a = 'a'; a < 'd'; a++) {
            Poltrona p = null;
            for (int i = 1; i < 11; i++) {
                p = new Poltrona();
                p.setTbVooVooCodigo(v);
                p.setPolNumero("" + a + i);
                p.setPolStatus(Boolean.FALSE);
                daoPoltrona.gravar(p);

            }
        }

        result.forwardTo(this).listavoo();
    }

    @Path("/listaVoos")
    public List<Voo> listavoo() {
        return dao.lista();
    }
}